package com.neuedu.his.service.impl;

import com.neuedu.his.mapper.UserMapper;
import com.neuedu.his.po.User;
import com.neuedu.his.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean register(User user) {
        try {
            int result = userMapper.insert(user);
            return result > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public User login(String userName, String password) {
        User user = userMapper.selectByUserName(userName);
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }

    @Override
    public List<User> findUsersByRealName(String realName) {
        return userMapper.selectByRealName(realName);
    }

    @Override
    public boolean deleteUserById(Integer id) {
        int result = userMapper.deleteUserById(id);
        return result > 0;
    }

    @Override
    public boolean updateUser(User user) {
        int result = userMapper.updateUser(user);
        return result > 0;
    }
}